<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="true" title="课程申报" back-icon-color='#333333' height="50" :border-bottom="false">
		</u-navbar>
		<view class="list">
			<view class="designation">
				<text>申报人</text>
				<text>{{teacher_name}}</text>
			</view>
			<view class="position">
				<text>在校职称</text>
				<text>{{form.school_position}}</text>
			</view>
			<view class="course">
				<text>课程名称</text>
				<text>{{form.name}}</text>
			</view>
			<view class="leave_reason">
				<text>内容简介</text>
				<text>{{form.introduction}}</text>
			</view>
			<view class="elective">
				<text class="elective_course">选修对象</text>
				<view class="gradeList" v-for="(item,index) in grade_list" :key="index">
					<view class="circle" :style="{borderColor:item.borderColor}">
						<text class="small_circle" :style="{background:item.background}"></text>
					</view>
					<text class="grade">{{item.label}}</text>
				</view>
			</view>
			<view class="student_require">
				<text>学生要求说明</text>
			</view>
			<view class=""
				style="width:710rpx; height:15rpx; margin-left:20rpx; background:#F2F2F2; border-top-left-radius:12rpx; border-top-right-radius:12rpx;">

			</view>
			<textarea value="" v-model="form.remark" placeholder="单行输入"
				style="width:710rpx; height:160rpx; margin-left:20rpx; background:#F2F2F2; text-indent:1em; border-bottom-left-radius:12rpx; border-bottom-right-radius:12rpx;" />
			<view class="handing">
				<text class="results">处理结果</text>
				<view class="toggle">
					<text :style="{color:left_color,background:left_background_color}"
						@click="changeLeftColor">通过</text>
					<text :style="{color:right_color,background:right_background_color}"
						@click="changeRightColor">驳回</text>
				</view>
			</view>
			<view class="remarks">
				<text>处理备注</text>
			</view>
			<view class=""
				style="width:710rpx; height:15rpx; margin-left:20rpx; background:#F2F2F2; border-top-left-radius:12rpx; border-top-right-radius:12rpx;">

			</view>
			<textarea value="" v-model="input_content" placeholder="单行输入"
				style="width:710rpx; height:160rpx; margin-left:20rpx; background:#F2F2F2; text-indent:1em; border-bottom-left-radius:12rpx; border-bottom-right-radius:12rpx;" />
			<view class="" style="width:100%; height:25rpx;">
			</view>
		</view>
		<view class="confirm">
			<view class="verify" @click="applyHandle">
				{{verify}}
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../request.js'
	export default {
		data() {
			return {
				left_color: '#fff',
				left_background_color: '#2E98FA',
				require_content: '',
				right_color: '#333333',
				right_background_color: '#F2F2F2',
				input_content: '',
				teacher_name: '',
				grade_list: [],
				form: {
					name: '',
					school_position: '',
					introduction: '',
					link_grade_ids: '',
					remark: "",
					elective_course_id: '',
					handle: 1,
				},
				verify: '确认'
			}
		},
		onLoad(option) {
			if (option) {
				this.teacher_name = option.teacher;
				this.form.school_position = option.position;
				this.form.name = option.subject;
				this.form.remark = option.remark;
				this.form.introduction = option.desc;
				this.form.link_grade_ids = option.id;
				this.form.elective_course_id = option.course_id;
			}
			this.gradeLists();
		},
		methods: {
			gradeLists() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'teacher/classes/gradeLists',
					method: 'post',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data);
							_this.grade_list = [];
							let dataList = [];
							let arr = [];
							dataList = res.data.data;
							if (_this.form.link_grade_ids) {
								arr = _this.form.link_grade_ids.split(',');
								dataList.forEach(item => {
									_this.grade_list.push({
										label: item.name,
										value: item.grade_id,
										borderColor: '#ccc',
										background: '#fff',
									})
								})
								for (let i = 0; i < _this.grade_list.length; i++) {
									for (let j = 0; j < arr.length; j++) {
										if (arr[j] == _this.grade_list[i].value) {
											_this.grade_list[i].background = '#17CE8B';
											_this.grade_list[i].borderColor = '#17CE8B';
										}
									}
								}
							
							} else {
								dataList.forEach(item => {
									_this.grade_list.push({
										label: item.name,
										value: item.grade_id,
										borderColor: '#ccc',
										background: '#fff',
									})
								})
							}
							
							console.log(_this.grade_list);
							console.log(_this.grade_list);
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			applyHandle() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'teacher/electiveCourse/applyHandle',
					data: {
						elective_course_id: this.form.elective_course_id,
						handle: this.form.handle,
						handle_remark:this.input_content,
					},
					method: 'post',
					success(res) {
						if (res.statusCode == 200) {
							_this.$toLink('../declare_course/declare_course', {}, 2);
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			changeLeftColor() {
				if (this.left_background_color == '#2E98FA') {
					this.left_color = '#333333';
					this.left_background_color = '#F2F2F2';
					this.right_color = '#fff';
					this.right_background_color = '#2E98FA';
				} else {
					this.left_color = '#fff';
					this.left_background_color = '#2E98FA';
					this.right_color = '#333333';
					this.right_background_color = '#F2F2F2';
					this.form.handle = 1;
				}
			},
			changeRightColor() {
				if (this.right_background_color == '#2E98FA') {
					this.right_color = '#333333';
					this.right_background_color = '#F2F2F2';
					this.left_color = '#fff';
					this.left_background_color = '#2E98FA';
				} else {
					this.right_color = '#fff';
					this.right_background_color = '#2E98FA';
					this.left_color = '#333333';
					this.left_background_color = '#F2F2F2';
					this.form.handle = 2;
				}
			},
		}
	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		overflow: hidden;
		background: #F2F2F2;

		.list {
			width: 100%;
			margin-top: 20rpx;
			background: #fff;

			.designation {
				width: 710rpx;
				margin-left: 20rpx;
				height: 60rpx;
				display: flex;
				justify-content: flex-start;

				text {
					margin-top: 25rpx;
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}

					&:nth-child(2) {
						color: #333333;
					}
				}
			}

			.position {
				width: 710rpx;
				margin-left: 20rpx;
				height: 60rpx;
				display: flex;
				justify-content: flex-start;

				text {
					margin-top: 25rpx;
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}

					&:nth-child(2) {
						color: #333333;
					}
				}
			}

			.course {
				width: 710rpx;
				margin-left: 20rpx;
				height: 60rpx;
				display: flex;
				justify-content: flex-start;

				text {
					margin-top: 25rpx;
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}

					&:nth-child(2) {
						color: #2E98FA;
					}
				}
			}

			.leave_reason {
				width: 710rpx;
				margin-left: 20rpx;
				height: 120rpx;
				display: flex;
				justify-content: flex-start;
				border-bottom: 1px solid #F2F2F2;


				text {
					margin-top: 25rpx;
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}

					&:nth-child(2) {
						color: #333333;
					}
				}
			}

			.elective {
				width: 710rpx;
				margin-left: 20rpx;
				height: 70rpx;
				display: flex;
				justify-content: flex-start;

				.elective_course {
					font-size: 26rpx;
					color: #666666;
					width: 150rpx;
					margin-top: 33rpx;
				}

				.gradeList {
					margin-top: 25rpx;
					height: 45rpx;
					width: 180rpx;
					overflow: hidden;
					display: flex;
					justify-content: flex-start;

					.circle {
						width: 30rpx;
						height: 30rpx;
						margin-top: 10rpx;
						border-radius: 50%;
						border: 3rpx solid #17CE8B;
						position: relative;

						.small_circle {
							width: 18rpx;
							height: 18rpx;
							position: absolute;
							left: 4rpx;
							top: 4rpx;
							background: #17CE8B;
							border-radius: 50%;
						}

					}

					.grade {
						margin-left: 10rpx;
						font-size: 26rpx;
						color: #333333;
						margin-top: 7rpx;
						width: 130rpx;
					}
				}

			}

			.student_require {
				width: 710rpx;
				margin-left: 20rpx;
				height: 80rpx;
				display: flex;
				justify-content: flex-start;

				text {
					font-size: 26rpx;
					margin-top: 30rpx;
					color: #666666;
					width: 250rpx;
				}
			}

			.handing {
				width: 710rpx;
				margin-left: 20rpx;
				height: 100rpx;
				align-items: center;
				display: flex;
				justify-content: flex-start;

				.results {
					width: 150rpx;
					color: #666666;
					font-size: 26rpx;
				}

				.toggle {
					width: 160rpx;
					height: 40rpx;
					position: relative;

					text {
						&:nth-child(1) {
							border-top-left-radius: 20rpx;
							border-bottom-left-radius: 20rpx;
							background: #2E98FA;
							color: #fff;
							text-align: center;
							line-height: 40rpx;
							height: 40rpx;
							font-size: 20rpx;
							width: 80rpx;
							position: absolute;
							top: 0;
							left: 0;
						}

						&:nth-child(2) {
							border-top-right-radius: 20rpx;
							border-bottom-right-radius: 20rpx;
							background: #F2F2F2;
							color: #333333;
							text-align: center;
							line-height: 40rpx;
							height: 40rpx;
							font-size: 20rpx;
							width: 80rpx;
							position: absolute;
							top: 0;
							left: 80rpx;
						}
					}
				}
			}

			.remarks {
				width: 710rpx;
				margin-left: 20rpx;
				height: 50rpx;
				display: flex;
				justify-content: flex-start;

				text {
					font-size: 26rpx;
					color: #666666;
					width: 150rpx;
				}
			}
		}

		.confirm {
			width: 100%;
			height: 300rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.verify {
				width: 200rpx;
				height: 60rpx;
				border-radius: 50rpx;
				text-align: center;
				line-height: 60rpx;
				background: linear-gradient(to right, #2C78FE, #32B0FF);
				color: #fff;
				font-size: 30rpx;
			}
		}
	}
</style>
